﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Steer
{
	public partial class SeekFleeTest1 : UserControl
    {
        public bool IsFocus = false;

        protected override void OnLostFocus(RoutedEventArgs e)
        {
            IsFocus = false;
            PauseMask.Visibility = IsFocus ? Visibility.Collapsed : Visibility.Visible;
            base.OnLostFocus(e);
        }

        protected override void OnGotFocus(RoutedEventArgs e)
        {
            IsFocus = true;
            PauseMask.Visibility = IsFocus ? Visibility.Collapsed : Visibility.Visible;
            base.OnGotFocus(e);
        }
		public SeekFleeTest1()
		{
			// Required to initialize variables
            InitializeComponent();
            Loaded += new RoutedEventHandler(SeekTest_Loaded);
        }

        void SeekTest_Loaded(object sender, RoutedEventArgs e)
        {
            mySeek.position = new Vector2D(200, 200);
            mySeek.edgeBehavior = Vehicle.BOUNCE;

            myflee.position = new Vector2D(100, 300);
            myflee.edgeBehavior = Vehicle.BOUNCE;

            CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
        }

        void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            if (IsFocus)
            {
                mySeek.seek(myflee.position);
                myflee.flee(mySeek.position);
                mySeek.update();
                myflee.update();
            }
        }
	}
}